// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	2/12/2015 10:46:27 PM				
// -----------------------------

#include "CPlatform.h"

#include "Path.h"

#include <concrt.h>

using namespace Platform;
using namespace Windows::Storage;
using namespace Windows::ApplicationModel;

namespace Flow
{

	CPlatform::CPlatform()
	{
	}

	CPlatform::~CPlatform()
	{
	}

	void CPlatform::Release()
	{
		delete this;
	}

	void CPlatform::Sleep(UInt32 milliseconds)
	{
		Concurrency::wait(milliseconds);
	}

	Platform::Enum CPlatform::GetPlatform() const
	{
		return Platform::WindowsPhone8;
	}
	Bool CPlatform::IsPlatform(Platform::Enum platform) const
	{
		return (GetPlatform() == platform);
	}

	UInt32 CPlatform::GetProcessorCount() const
	{
		return 1;
	}
	tstring CPlatform::GetRootFolder() const
	{
		Package^ package = Package::Current;
		// WORKAROUND: package->Id not implemented on Windows Phone 8
		PackageId^ packageId = Windows::Phone::Management::Deployment::InstallationManager::FindPackagesForCurrentPublisher()->First()->Current->Id;

		String^ path = package->InstalledLocation->Path;
		String^ name = packageId->Name;
		#ifdef _DEBUG
		name = name + "_Debug";
		#else
		name = name + "_Release";
		#endif
		name = name + "_ARM";
		
		tstring strPath = tstring(path->Data());
		tstring strName = tstring(name->Data());
		tstring root = Path::Combine(strPath, strName);

		return root;
	}

	UInt32 CPlatform::GetCurrentThreadID() const
	{
		return (UInt32) ::GetCurrentThreadId();
	}

}